package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.pojo.entity.OrderSetting;
import com.itheima.health.pojo.result.Result;
import com.itheima.health.service.OrdersSettingService;
import lombok.extern.slf4j.Slf4j;
import com.itheima.health.pojo.vo.OrderSettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/ordersetting")
public class OrdersSettingController {

    @Autowired
    private OrdersSettingService ordersSettingService;

    /**
     * 预约管理-上传文件-当月预约设置接口
     * 当月预约信息展示
     * @param year
     * @param month
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(Integer year, Integer month) {
        List<OrderSettingVo> setting = ordersSettingService.getOrderSettingByMonth(year, month);
        return new Result(true, MessageConst.QUERY_ORDER_SUCCESS, setting);
    }

    @PostMapping("/upload")
    public Result upload(MultipartFile excelFile){
        log.info("预约管理，上传文件：{}", excelFile);
        Boolean flag = ordersSettingService.upload(excelFile);
        if(flag) {
            return new Result(true, MessageConst.IMPORT_ORDERSETTING_SUCCESS);
        }
        return new Result(false, MessageConst.IMPORT_ORDERSETTING_FAIL);
    }



    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody OrderSetting orderSetting) {
        log.info("编辑预约设置");
        ordersSettingService.editNumberByDate(orderSetting);
        return new Result(true, "编辑预约设置成功");
    }
}
